<?php

/**
 * ExtrasCampo form.
 *
 * @package    cronos-doctrine
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ExtrasCampoForm extends BaseExtrasCampoForm
{
  public function configure()
  {
      
      $this->removeField();
      
      $this->widgetSchema['empresa_id'] = new sfWidgetFormInputHidden(array(),array('value'=> sfContext::getInstance()->getUser()->getAttribute('agente_user_empresa_id')));
      
       if($this->isNew()){       
            $this->choice();
      }else {
           if($this->getObject()->getCamposEtiqueta()->getRequired()) {
                $this->widgetSchema['campos_etiquetas_id'] = new sfWidgetFormInputHidden();
                $this->widgetSchema->setLabels(array('campos_etiquetas_id'    => $this->getObject()->getCamposEtiqueta()));
                $this->widgetSchema['mostrar_etiqueta'] = new sfWidgetFormInputHidden(array(),array('value' => false));
                $this->validatorSchema['mostrar_etiqueta'] = new sfValidatorPass();
           }else {
              $this->choice(); 
           }        
       }
  }
  
  protected function choice() {
     $this->widgetSchema['campos_etiquetas_id'] = new sfWidgetFormDoctrineChoice(array(
            'multiple' => false, 
            'model' => 'CamposEtiqueta',
            'query' => $this->getObject()->getCamposEtiqueta()->getTable()->getCamposE(0),
            'expanded' => false));
  }
  
   protected function removeField() {
      //Eliminar los campos del formularios  created_at y updated_at
       unset (
        $this['created_at'],
        $this['updated_at'],
        $this['usuario_id']

      );
       
       $this->widgetSchema->setLabels(array(
        'campos_etiquetas_id'    => false,
       ));

  }
}
